package org.jeecg.modules.identificationRecord.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.identificationRecord.entity.IdentificationRecord;
import org.jeecg.modules.identificationRecord.entity.IdentificationRecordDTO;
import org.jeecg.modules.identificationRecord.mapper.IdentificationRecordMapper;
import org.jeecg.modules.identificationRecord.service.IIdentificationRecordService;
import org.jeecg.modules.scheduling.entity.CardVO;
import org.jeecg.modules.scheduling.entity.SchedulingVO;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Description: 人像识别记录表
 * @Author: jeecg-boot
 * @Date:   2025-01-16
 * @Version: V1.0
 */
@Service
public class IdentificationRecordServiceImpl extends ServiceImpl<IdentificationRecordMapper, IdentificationRecord> implements IIdentificationRecordService {

    @Override
    public IdentificationRecord getLastByAdmitGuid(String admitGuid) {
        LambdaQueryWrapper<IdentificationRecord> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(IdentificationRecord::getAdmitGuid, admitGuid);
        wrapper.orderByDesc(IdentificationRecord::getCreateTime);
        wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public IdentificationRecord getTodayLastByAdmitGuid(String admitGuid) {
        String s = DateUtils.formatDate("yyyy-MM-dd");
        QueryWrapper<IdentificationRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("admit_guid", admitGuid);
        wrapper.eq("DATE(create_time)", s);
        wrapper.orderByDesc("create_time");
        wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public IdentificationRecord getTodayEarlyByAdmitGuid(String admitGuid) {
        String s = DateUtils.formatDate("yyyy-MM-dd");
        QueryWrapper<IdentificationRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("admit_guid", admitGuid);
        wrapper.eq("DATE(create_time)", s);
        wrapper.orderByAsc("create_time");
        wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }

}
